﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;

namespace Nsf.Samples.RetryActivitySample.WorkflowBase.Activities
{
    [Designer(typeof(RetryableCodeActivityDesigner), typeof(IDesigner))]
	public partial class RetryableCodeActivity: RetryableActivity
    {
        #region Design

        private class RetryableCodeActivityDesignerTheme : ActivityDesignerTheme
        {
            private void InitializeTheme()
            {
                this.ForeColor = Color.FromArgb(0xff, 0, 0, 0);
                this.BorderColor = Color.FromArgb(0xff, 0x73, 0x79, 0xbd);
                this.BorderStyle = DashStyle.Solid;
                this.BackColorStart = Color.FromArgb(0xff, 0xff, 0xf9, 0xff);
                this.BackColorEnd = Color.FromArgb(0xff, 0xff, 0xf0, 0x6c);
                this.BackgroundStyle = LinearGradientMode.Horizontal;
            }

            public RetryableCodeActivityDesignerTheme(WorkflowTheme workflowTheme)
                : base(workflowTheme)
            {
                InitializeTheme();
            }


        }

        [ActivityDesignerTheme(typeof(RetryableCodeActivityDesignerTheme))]
        private class RetryableCodeActivityDesigner : ActivityDesigner
        {

        }

        #endregion

        #region Dependency Properties

        public static readonly DependencyProperty ExecuteCodeEvent =
            DependencyProperty.Register("ExecuteCode",
                                        typeof(EventHandler),
                                        typeof(RetryableCodeActivity));


        #endregion

        #region Events

        public event EventHandler ExecuteCode
        {
            add { AddHandler(ExecuteCodeEvent, value); }
            remove { RemoveHandler(ExecuteCodeEvent, value); }
        }

        #endregion

        #region Constructors

        public RetryableCodeActivity()
        {
            InitializeComponent();
        }

        public RetryableCodeActivity(String name)
            : base(name)
        {
            InitializeComponent();
        }

        #endregion

        #region Overrides

        public override ActivityExecutionStatus OnExecute(ActivityExecutionContext executionContext)
        {
            RaiseEvent(ExecuteCodeEvent, executionContext, EventArgs.Empty);
            return ActivityExecutionStatus.Closed;
        }

        #endregion
    }
}
